<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子7-ES6/7常用语法介绍</title>
    </head>
    <body>
        <pre>
            <code>
                // 例子7

                let [a, b, c] = [1, 2, 3]; // 相当于 let a = 1; let b = 2; let c = 3;
                console.log(a, b, c); // 1 2 3

                let [foo, [[bar], baz]] = [1, [[2], 3]];
                console.log(foo, bar, baz); // 1 2 3

                let [, , third] = ['foo', 'bar', 'baz'];
                console.log(third); // "baz"

                //-------------------------------------------------

                let [x, , y] = [1, 2, 3];
                console.log(x, y); // 1 3

                //-------------------------------------------------

                let [head, ...tail] = [1, 2, 3, 4];
                console.log(head, tail); // 1 [2, 3, 4]

                //-------------------------------------------------

                let [x, y, ...z] = ['a'];
                console.log(x, y, z); // "a" undefined [],其中y匹配失败，为undefined

                //-------------------------------------------------

                let [x, y] = [1, 2, 3]; // 不完全解构
                console.log(x, y); // 1 2
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/7.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>